import logging

from capsserver.lib.base import *

from indra.base.uuid import uuid1
from indra.base.llsd import parse

log = logging.getLogger(__name__)

class MainController(BaseController):

    def index(self):
        # Return a rendered template
        #   return render('/some/template.mako')
        # or, Return a response
        return 'Hello World'
        
    def register(self):
        """register a new caps"""
        cap = model.Capability()
        import pdb; pdb.set_trace()
        data = request.POST['data']
        print data
        data = parse(data)
        cap.origin = data['origin']
        cap.title = data['title']
        cap.uuid = str(uuid1())

        scheme = request.scheme
        host = request.host
        url = "%s://%s/cap/%s" %(scheme,host,cap.uuid)
        cap.url = url
        
        print url
        
        model.Session.save(cap)
        model.Session.commit()
        
        return url
        
    
